package com.example.filterPattern.criteria;

import com.example.filterPattern.Person;

import java.util.List;

/**
 * or 标准
 * sun 2017-12-15
 */
public class OrCriteria implements Criteria {
    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    @Override
    public List<Person> meetCriteria(List<Person> persons) {
       List<Person> firstItems = criteria.meetCriteria(persons);
       List<Person> otherItems = otherCriteria.meetCriteria(persons);

       for(Person p : otherItems){
           if(!firstItems.contains(p)) firstItems.add(p);
       }
        return firstItems;
    }
}
